package org.ljy.testdemo.aspect;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 实现自定义注解 -- @CostTime
 */

@Slf4j
@Component
@Aspect
public class CostTimeAspect {

    @SneakyThrows //捕获异常
    @Around("@annotation(org.ljy.testdemo.aspect.CostTime)")
    public Object costTime(ProceedingJoinPoint joinPoint)  {
        long startTime = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        log.info( joinPoint.getSignature().toLongString()+"耗时:"+ ( System.currentTimeMillis() - startTime )+"ms");
        return result;
    }

}
